<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/4/15 16:17
 * Remark:
 */

namespace App\Http\Controllers\Auth;

use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\AddRolePost;
use App\Http\Requests\Contract\ListContractTypeGet;
use App\Service\Auth\RoleService;

class RoleController extends Controller
{
    private RoleService $_roleService;

    public function __construct()
    {
        $this->middleware([
           'roleLeg'
        ]);
        $this->_roleService = new RoleService();
    }

    /**
     * @param AddRolePost $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addRole(AddRolePost $request): \Illuminate\Http\JsonResponse
    {

		print_r('xxxxxxxx');
		die;

        $data = $request->all();
        $res =  $this->_roleService->addRole($data);
        return ResponseFunc::returnJson(
            'ok',
            [
                "contract_type_id" =>$res
            ],
            '新增角色成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 修改角色
     * @param int $roleId
     * @return \Illuminate\Http\JsonResponse
     */
    public function editRole(int $roleId): \Illuminate\Http\JsonResponse
    {
        $data = request()->post();
        $data['role_id'] = $roleId;
        $this->_roleService->editRole($data);
        return ResponseFunc::returnJson(
            'ok',
            null,
            '修改角色成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 删除角色
     * @param int $roleId
     * @return \Illuminate\Http\JsonResponse
     */
    public function deleteRole(int $roleId): \Illuminate\Http\JsonResponse
    {
        $this->_roleService->deleteRole($roleId);
        return ResponseFunc::returnJson(
            'ok',
            null,
            '删除角色成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取合同详情
     * @param int $roleId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRoleInfo(int $roleId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_roleService->getRoleInfo($roleId),
            '获取角色详情成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取角色下拉
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRoleSelect(): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_roleService->getRoleSelect(),
            '获取角色下拉成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 根据部门ID获取角色下拉
     * @param ListContractTypeGet $request
     * @return mixed
     */
    public function getRoleList(ListContractTypeGet $request): mixed
    {
		

        $pageSize = $request->get('page_size');
        $filters = $request->get('filters');
        return ResponseFunc::returnJson(
            'ok',
            $this->_roleService->getRoleList($pageSize,$filters),
            '获取角色列表成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }

    /**
     * @param $roleId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRoleAuthMenu($roleId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_roleService->getRoleAuthMenu($roleId),
            '获取角色列表成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }
}